package com.holly.unit.customer.starter;

import com.holly.unit.cache.api.CacheOperatorApi;
import com.holly.unit.cache.redis.util.CreateRedisTemplateUtil;
import com.holly.unit.customer.api.pojo.CustomerInfo;
import com.holly.unit.customer.modular.cache.CustomerRedisCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * C端自动装配
 *
 * @author holly
 * @date 2021/6/7 11:32
 */
@Configuration
public class HollyCustomerAutoConfiguration {

//    /**
//     * C端用户的缓存
//     *
//     * @author holly
//     * @date 2021/6/8 22:41
//     */
//    @Bean
//    @ConditionalOnMissingBean(name = "customerInfoCacheOperatorApi")
//    public CacheOperatorApi<CustomerInfo> customerInfoCacheOperatorApi() {
//        TimedCache<String, CustomerInfo> customerInfoTimedCache = CacheUtil.newTimedCache(CustomerConfigExpander.getCustomerCacheExpiredSeconds() * 1000);
//        return new CustomerMemoryCache(customerInfoTimedCache);
//    }

    /**
     * C端用户的缓存
     *
     * @author holly
     * @date 2021/6/8 22:41
     */
    @Bean
    @ConditionalOnMissingBean(name = "customerInfoCacheOperatorApi")
    public CacheOperatorApi<CustomerInfo> customerInfoCacheOperatorApi(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, CustomerInfo> customerInfoRedisCache = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
        return  new CustomerRedisCache(customerInfoRedisCache);
    }
}
